﻿
function Buy(ModelId, GoodsID)
{
    try
    {
        window.open("../../Shop/Buy.aspx?Action=Buy&ModelId=" + ModelId + "&GoodsID=" + GoodsID);
    }
    catch (e)
    {
        window.location = "../../Shop/Buy.aspx?Action=Buy&ModelId=" + ModelId + "&GoodsID=" + GoodsID;
    }
}
function ShowShopingCart(ModelId)
{
    var parameters = "ModelId=" + ModelId;
    $.ajax({
        type: "POST",
        url: "../../AjaxPostBack.ashx?Action=ShowShopingCart",
        data: parameters,
        dataType: "JSON",
        beforeSend: function () { },
        success: function (info)
        {
            if (info == null)
            {
                if ($("#ShoppingCart_bar")) $("#ShoppingCart_bar").text("0");

                if ($("#GoodsQuantity")) $("#GoodsQuantity").text("0");
                if ($("#PriceTotal")) $("#PriceTotal").text("0");
                if ($("#CartUrl")) $("#CartUrl").attr("href", "javascript:alert('购物车为空！');");
            }
            else
            {
                if ($("#ShoppingCart_bar")) $("#ShoppingCart_bar").text(info.GoodsQuantity);
                if ($("#PriceTotal_bar")) $("#PriceTotal_bar").text(info.PriceTotal);

                if ($("#GoodsQuantity")) $("#GoodsQuantity").text(info.GoodsQuantity);
                if ($("#PriceTotal")) $("#PriceTotal").text(info.PriceTotal);
                if ($("#CartUrl")) $("#CartUrl").attr("href", info.CartUrl);

            }
        }
    });
}

function JoinCart(ModelId, GoodsID)
{
    var parameters = "ModelId=" + ModelId;
    parameters += "&GoodsID=" + GoodsID;
    $.ajax({
        type: "POST",
        url: "../../AjaxPostBack.ashx?Action=JoinCart",
        data: parameters,
        dataType: "JSON",
        beforeSend: function () { },
        success: function (msg)
        {
            ShowShopingCart(ModelId);
            alert("添加成功");
        }
    });
}



 
 

function ShowDetail(id)
{
    $("#myDetailshow").html("<img src='/ajax/reading.gif' />内容读取中");
    $("#showdetail").addClass("ctitle01");
    $("#showdetail").removeClass("ctitle02");
    $("#showparameter").addClass("ctitle02");
    $("#showparameter").removeClass("ctitle01");
    $.ajax({
        type: "POST",
        url: "/ajax/api_ajax.asp",
        data: "act=showdetail&productid=" + id,
        success: function (msg)
        {
            $("#myDetailshow").html(msg);
        }
    });
}

function ShowParameter(id)
{
    $("#myDetailshow").html("<img src='/ajax/reading.gif' />内容读取中");
    $("#showdetail").removeClass("ctitle01");
    $("#showdetail").addClass("ctitle02");
    $("#showparameter").removeClass("ctitle02");
    $("#showparameter").addClass("ctitle01");
    $.ajax({
        type: "POST",
        url: "/ajax/api_ajax.asp",
        data: "act=showparameter&productid=" + id,
        success: function (msg)
        {
            $("#myDetailshow").html(msg);
        }
    });
}

function showComment(productid, pageid)
{
    $("#pllist").html("<img src='/ajax/reading.gif' />内容读取中");
    $.ajax({
        type: "POST",
        url: "/ajax/api_ajax.asp",
        data: "act=showcommentdetail&productid=" + productid + "&page=" + pageid,
        success: function (msg)
        {
            $("#pllist").html(msg);
        }
    });

}

var strhtml, idd;

function showTime()
{
    document.getElementById("lwsubmin").innerHTML = strhtml;
    clearInterval(idd);
}

//保存留言
function savecomment(id)
{
    var content = document.getElementById("content").value;
    var UserName = document.getElementById("UserName").value;
    var point = 0;
    for (i = 1; i <= 5; i++)
    {
        if (document.getElementById("point" + i).checked)
            point = document.getElementById("point" + i).value;
    }
    if (UserName.length < 2)
    {
        document.getElementById("UserName").focus();
        alert("请填写您的名字,名字长度不能少于2！");
    }
    else
    {
        if (content.length > 100 || content.length < 3)
        {
            document.getElementById("content").focus();
            alert("提问不要超过100字,且不要少于3个字。");
        }
        else
        {
            document.getElementById("content").value = '';
            document.getElementById("UserName").value = '';
            $.ajax({
                type: "post",
                url: "/ajax/savecomment.asp",
                data: "Act=savecomment&content=" + content + "&UserName=" + UserName + "&id=" + id + "&point=" + point,
                success: function (msg)
                {
                    var vback = msg.split('|#|');
                    if (vback[0] == 'False')
                    {
                        alert(vback[1]);
                    }
                    else
                    {
                        strhtml = document.getElementById("lwsubmin").innerHTML;
                        document.getElementById("lwsubmin").innerHTML = "<div style=\"padding:5px;margin:5px;width:350px;text-align:center;color:#f6ab35;border:1px solid #f6ab35;\">" + vback[1] + "</div>";
                        idd = setInterval("showTime()", 5000);

                    }
                }
            });


        }
    }
}
function onmouseshowtext(obj, text)
{

    var noticeX = $(obj).offset().left;
    var noticeT = $(obj).offset().top;
    var noticeW = $(obj).width();
    var noticeH = $(obj).height();

    var x = noticeX - 70;
    var y = noticeT + noticeH + 5;


    document.getElementById("showtext").style.display = '';
    document.getElementById("showtext").innerHTML = text;
    document.getElementById("showtext").style.left = x + "px";
    document.getElementById("showtext").style.top = y + "px";

}
 